<%@page import="com.zhuoshi.bean.ContractSubBean"%>
<%@page import="com.zhuoshi.dao.ContractSubDao"%>
<%@page import="com.zhuoshi.bean.ContractMasterBean"%>
<%@page import="com.zhuoshi.dao.ContractMasterDao"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
request.setCharacterEncoding("UTF-8");
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
//合同数字编号
ContractMasterDao dao = new ContractMasterDao();
List<ContractMasterBean> list = dao.getAllList();
pageContext.setAttribute("list", list);

String action = request.getParameter("action");
if("add".equals(action)){
	//out.print("准备开始添加操作");
	String sparename = request.getParameter("spare");
	String numerical = request.getParameter("numerical");
	String modeltype = request.getParameter("model");
	String unit = request.getParameter("prickle");
	String price = request.getParameter("price");
	
	String totalcount = request.getParameter("amount");
	double totalmoney = Double.parseDouble(price) * Integer.parseInt(totalcount);
	
	//out.print(totalmoney);
	
	ContractSubDao csDao = new ContractSubDao();
	ContractSubBean csBean = new ContractSubBean();
	csBean.setNumerical(Integer.parseInt(numerical));
	csBean.setSqarename(sparename);
	csBean.setModeltype(modeltype);
	csBean.setUnit(unit);
	csBean.setPrice(Double.parseDouble(price));
	csBean.setTotalcount(Integer.parseInt(totalcount));
	csBean.setTotalmoney(totalmoney);
	int rows = csDao.add(csBean);
	if(rows>0){
		out.print("<script language='javascript'>alert('添加成功');location.href='contractsub_add.jsp';</script>");
	}
	
}

%>


<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
<meta http-equiv="Cache-Control" content="no-siteapp">
<link rel="Bookmark" href="http://localhost:8080/favicon.ico">
<link rel="Shortcut Icon" href="http://localhost:8080/favicon.ico">
<!--[if lt IE 9]>
<script type="text/javascript" src="lib/html5.js"></script>
<script type="text/javascript" src="lib/respond.min.js"></script>
<script type="text/javascript" src="lib/PIE_IE678.js"></script>
<![endif]-->
<link rel="stylesheet" type="text/css" href="template/H-ui.min.css">
<link rel="stylesheet" type="text/css" href="template/H-ui.admin.css">
<link rel="stylesheet" type="text/css" href="template/iconfont.css">
<link rel="stylesheet" type="text/css" href="template/icheck.css">
<link rel="stylesheet" type="text/css" href="template/skin.css" id="skin">
<link rel="stylesheet" type="text/css" href="template/style.css">


<title>添加合同明细 </title>


<script type="text/javascript">
	function test()
{
		//var x = document.getElementById('contractnum').value;
		//var date = (new Date()).getFullYear();
		
		
	
	 var numerical = document.getElementById('numerical').value;
		  if(numerical ==""){
			 document.form.numerical.focus();
           return false; 
		  }
	 var spare = document.getElementById('spare').value;
		  if(spare ==""){
			 document.form.spare.focus();
           return false; 
		  }
	 var model = document.getElementById('model').value;
		  if(model ==""){
			 document.form.model.focus();
           return false; 
		  }
		  
	 var prickle = document.getElementById('prickle').value;
		  if(prickle ==""){
			 document.form.prickle.focus();
           return false; 
		  }
	 var amount = document.getElementById('amount').value;
		  if(amount ==""){
			 document.form.amount.focus();
           return false; 
		  }
	 var price = document.getElementById('price').value;
		  if(price ==""){
			 document.form.price.focus();
           return false; 
		  }
	return true;
}	  
</script><link rel="stylesheet" href="layer.css" id="layui_layer_skinlayercss"><link href="WdatePicker.css" rel="stylesheet" type="text/css"></head>



<body>
<article class="page-container">
	<form action="?action=add" name="form" method="post" class="form form-horizontal" id="form-member-add" onSubmit="return test(this)">
		
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>合同数字编号：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<select name="numerical" id="numerical" class="input-text" placeholder="" style="width:350px">
				<option value="">---请选择合同数字编号---</option>
				<c:forEach items="${list }" var="cmBean">
				<option value="${cmBean.numerical }">${cmBean.numerical }</option>
				</c:forEach>
				</select>
			</div>
		</div>
		
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>备件名称：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="" placeholder="" id="spare" name="spare" style="width:350px">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>规格型号：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" placeholder="" name="model" id="model" style="width:350px">
			</div>
		</div>
		
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>计量单位：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" placeholder="" name="prickle" id="prickle" style="width:350px">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>总数：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" placeholder="" name="amount" id="amount" style="width:350px">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>单价：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" placeholder="" name="price" id="price" style="width:350px">
			</div>
		</div>
		
		<div class="row cl">
			<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
				<input class="btn btn-primary radius" id="send" type="submit" value="  提交  ">
				<input type="button" class="btn btn-danger radius" id="transmit" value="关闭并返回" />
			</div>
		</div>
	</form>
</article>

<script type="text/javascript" src="template/jquery.min.js"></script> 
<script type="text/javascript" src="template/layer.js"></script>
<script type="text/javascript" src="template/laypage.js"></script> 
<script type="text/javascript" src="template/jquery.icheck.min.js"></script>
<script type="text/javascript" src="template/WdatePicker.js"></script> 
<script type="text/javascript" src="template/jquery.dataTables.min.js"></script> 
<script type="text/javascript" src="template/jquery.validate.min.js"></script> 
<script type="text/javascript" src="template/validate-methods.js"></script> 
<script type="text/javascript" src="template/messages_zh.min.js"></script>
<script type="text/javascript" src="template/H-ui.js"></script><a href="javascript:void(0)" class="Hui-iconfont toTop" title="返回顶部" alt="返回顶部" style="display:none"></a> 
<script type="text/javascript" src="template/H-ui.admin.js"></script> 



 
<script type="text/javascript">
$(function(){ 
       //如果是必填的，则加红星标识. 
       $("form :input.required").each(function(){ 
           var $required = $("<strong class='high'> *</strong>"); //创建元素 
           $(this).parent().append($required); //然后将它追加到文档中 
       }); 
        //文本框失去焦点后 
       $('form :input').blur(function(){ 
            var $parent = $(this).parent(); 
            $parent.find(".formtips").remove(); 
            //验证合同数字编号 
            if( $(this).is('#numerical') ){ 
                   if( this.value=="" || this.value.length != 6 ||isNaN(this.value) == true){ 
                       var errorMsg = '合同数字编号不能为空.';
                      
                       $parent.append('<span class="formtips onError" style="color:red">'+errorMsg+'</span>'); 
                   }else{ 
                       //$parent.append('<span class="formtips onSuccess" style="color:green"></span>'); 
                   check(this.value);
                   function check(contractnum){
              $.ajax({
            //提交数据的类型 POST GET
            type:"POST",
            //提交的网址
            url:"contractdetailnumcheck",
            //提交的数据
            data:{contractnum:contractnum},
            //返回数据的格式
            datatype: "text",//"xml", "html", "script", "json", "jsonp", "text".
            //在请求之前调用的函数
            //beforeSend:function(){$("#msg").html("logining");},
            //成功返回之后调用的函数             
            success:function(data){
            if(data=="存在此合同编号"){
            	$parent.append('<span class="formtips onSuccess" style="color:green"></span>');
            }else{
           		$parent.append('<span class="formtips onError" style="color:red">'+data+'</span>');
           		}            
            }  ,
            //调用执行后调用的函数
            complete: function(XMLHttpRequest, textStatus){
            },
            //调用出错执行的函数
            error: function(){
                //请求出错处理
            }         
         });}}}
            //验证备件 
           if( $(this).is('#spare') ){ 
                   if( this.value=="" ){ 
                       var errorMsg = '备件名称不能为空.';
                      
                       $parent.append('<span class="formtips onError" style="color:red">'+errorMsg+'</span>'); 
                   }else{ 
                       
                       $parent.append('<span class="formtips onSuccess" style="color:green"></span>'); 
                   } 
            } 
            //验证规格型号 
            if( $(this).is('#model') ){ 
               if( this.value==""  ){ 
                     var errorMsg = '规格型号不能为空.'; 
                     $parent.append('<span class="formtips onError" style="color:red">'+errorMsg+'</span>'); 
               }else{ 
                   
                     $parent.append('<span class="formtips onSuccess" style="color:green"></span>'); 
               } 
            } 
              //验证备注
            if( $(this).is('#remark') ){ 
             if(this.length!=0){ 
                   
                     $parent.append('<span class="formtips onSuccess" style="color:green"></span>'); 
               } 
            }
            
            //验证计量单位 
            if( $(this).is('#prickle') ){ 
               if( this.value==""  ){ 
                     var errorMsg = '计量单位不能为空.'; 
                     $parent.append('<span class="formtips onError" style="color:red">'+errorMsg+'</span>'); 
               }else{ 
                    
                     $parent.append('<span class="formtips onSuccess" style="color:green"></span>'); 
               } 
            } 
            
            
            //验证数量
            if( $(this).is('#amount') ){ 
                   if(this.value=="" ||  isNaN(this.value) == true  ){ 
                       var errorMsg = '请输入数字.'; 
                       $parent.append('<span class="formtips onError" style="color:red">'+errorMsg+'</span>'); 
                   }else{ 
                      
                       $parent.append('<span class="formtips onSuccess" style="color:green"></span>'); 
                   } 
            } 
            
            //验证单价 
            if( $(this).is('#price') ){ 
               if( this.value=="" ){ 
                     var errorMsg = '单价不能为空.'; 
                     $parent.append('<span class="formtips onError" style="color:red">'+errorMsg+'</span>'); 
               }
               else if(isNaN(this.value) == true ){
               		var errorMsg = '单价必须为数字.'; 
                     $parent.append('<span class="formtips onError" style="color:red">'+errorMsg+'</span>'); 
               }
               else{ 
                      
                     $parent.append('<span class="formtips onSuccess" style="color:green"></span>'); 
               } 
            } 
            
           
       }).keyup(function(){ 
          $(this).triggerHandler("blur"); 
       }).focus(function(){ 
            $(this).triggerHandler("blur"); 
       });//end blur 
       
       //提交，最终验证。 
        $('#send').click(function(){ 
               $("form :input.required").trigger('blur'); 
               var numError = $('form .onError').length; 
               if(numError!=0){ 
                   return false; 
               } else{
               return true;
               }
           
        });  
})
</script> 
<script type="text/javascript">
    $('#transmit').on('click', function(){
        //刷新页面
        parent.window.location.href='contractsublist.jsp';
        //获取窗口索引
        var index = parent.layer.getFrameIndex(window.name);
        //关闭弹出层
        parent.layer.close(index);
    });
</script>

</body></html>